const $api = require('./../../utils/request').API;

// pages/yuyuemsg/yuyuemsg.js
import Toast from '@vant/weapp/toast/toast'
import Dialog  from '@vant/weapp/dialog/dialog'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    active: '0',
    more: true,
    list: [],
    pageSize: 5,
    pageNum: 1,
    loading:false
  },

  onClick(event) {
    this.setData({
      active: event.detail.name,
      pageSize: 5,
      pageNum: 1,
      list:[],
    });
    this.getData();

  },

  getData(){
    wx.showLoading({
      title: '正在加载',
    })
    this.setData({
      loading:true
    })
      let params = {
        jishi:wx.getStorageSync('gongHao'),
        yuyueStatus:this.data.active == '0'? '':Number(this.data.active),
        pageSize: this.data.pageSize,
        pageNum: this.data.pageNum
      };
      $api.getYuyueData(params).then(res=>{
        wx.hideLoading({
          fail:()=>{},
          success:()=>{},
          complete: (complete) => {}
        })
        wx.stopPullDownRefresh();
        let arr = this.data.list;
        arr =  arr.concat(res.data.list);
        this.setData({
          list:arr,
          loading:false,
          more:arr.length>= res.data.totalCount? false:true
        })
      }).catch(err=>{
        wx.hideLoading({
          fail:()=>{},
          success:()=>{},
          complete: (complete) => {}
        })
        wx.stopPullDownRefresh();
        this.setData({
          loading:false
        })
      })
  },







  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.selectComponent('#header').resize();
    this.getData();
    

  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({ 
      list: [],
      pageNum:1,
    })
    this.getData();
  },

 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.more) {
      let pagenum = this.data.pageNum;
      this.setData({
        pageNum:pagenum+1
      });
      this.getData();
    }

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})